import "./public-path"
import React from "react"
import { BrowserRouter } from "react-router-dom"
import ReactDOM from "react-dom/client"
import "./index.css"
import App from "./App"

function render(props?: any) {
  const { container } = props
  const rootContainer = container
    ? container.querySelector("#root")
    : document.querySelector("#root")
  const root = ReactDOM.createRoot(rootContainer)
  root.render(
    <BrowserRouter basename={window.__POWERED_BY_QIANKUN__ ? "/pm-react" : "/"}>
      <App />
    </BrowserRouter>
  )
}
if (!(window as any).__POWERED_BY_QIANKUN__) {
  render({})
}

export async function bootstrap() {
  console.log("[react16] react app bootstraped")
}

export async function mount(props: any) {
  console.log("[react16] props from main framework", props)
  render(props)
}
export async function unmount(props: any) {
  // const { container } = props
  // const rootContainer = container
  //   ? container.querySelector("#root")
  //   : document.querySelector("#root")
  // const root = ReactDOM.createRoot(rootContainer) // 获取 root 实例
  // root.unmount() // 使用 root.unmount() 卸载组件
}
